import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import tsconfigPaths from 'vite-tsconfig-paths'

// eslint-disable-next-line import/no-anonymous-default-export
export default ({ mode }: { mode: string }) => {
  const http = loadEnv(mode, process.cwd())

  return defineConfig({
    plugins: [react(), tsconfigPaths()],
    server: {
      open: false,
      https: false,
      strictPort: true,
      proxy: {
        '/api': {
          target: http.VITE_BASR_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        '#': resolve(__dirname, './src/types')
      }
    }
  })
}
